using FrameWork;
using UnityEngine;

public class GoInstance : ObjectBase
{
    private GameObject _go;

    public GameObject Go { get => _go; }

    private int _goId;

    /// <summary>
    /// GameObject Id
    /// </summary>
    public int GoId { get => _goId; }

    protected internal override void OnSpawn()
    {
        if (Go.activeSelf == false)
            Go.SetActive(true);
    }

    protected internal override void OnUnSpawn()
    {
        if (Go.activeSelf)
            Go.SetActive(false);
    }

    protected internal override void Release()
    {
        if (Go != null)
        {
            GameObject.Destroy(Go);
        }
    }

    public static GoInstance CreateInstance(GameObject go,string path,int id)
    {
        var goInstance = ReferencePool.Acquire<GoInstance>();
        goInstance._go = go;
        goInstance.Init(path, go);
        goInstance._goId = id;
        return goInstance;
    }
}
